qx.Class.define("qx.ui.form.ow.Page",
{
	extend : qx.ui.embed.Iframe,
	construct : function (width, height, noCSS)
	{
		this.base(arguments);

		if (width != null) {
			this._width = width;
		}
		else {
			this._width = 550;
		}

		if (height != null) {
			this._height = height;
		}
		else {
			this._height = 300;
		}

		if (noCSS != null) {
			this._noCSS = noCSS;
		}
		else {
			this._noCSS = true;
		}

		this.addListenerOnce("load", function () {
			this._document = this.getWindow().document;
			this._document.designMode = 'on';

			if (this._noCSS) {
				try 
				{
					this._document.execCommand("styleWithCSS", 0, false);
				}
				catch (e) {
					try
					{
						this._document.execCommand("useCSS", 0, true);
					} 
					catch (e) {}
				}
			}
		}, this);

		this.setBackgroundColor("#FFFFFF");
		this.setWidth(this._width);
		this.setHeight(this._height);
	},
	members : {
		_document : null,
		_width : null,
		_height : null,
		_noCSS : null,
		undo : function ()
		{
			this._document.execCommand("undo",false,null);
		},
		redo : function ()
		{
			this._document.execCommand("redo",false,null);
		},
		bold : function ()
		{
			this._document.execCommand("bold",false,null);
		},
		italic : function ()
		{
			this._document.execCommand("italic",false,null);
		},
		underline : function ()
		{
			this._document.execCommand("underline",false,null);
		},
		strikethrough : function ()
		{
			this._document.execCommand("strikethrough",false,null);
		},
		alignLeft : function ()
		{
			this._document.execCommand("justifyleft",false,null);
		},
		alignCenter : function ()
		{
			this._document.execCommand("justifycenter",false,null);
		},
		alignRight : function ()
		{
			this._document.execCommand("justifyright",false,null);
		},
		alignJustify : function ()
		{
			this._document.execCommand("justifyfull",false,null);
		},
		indentDecrease : function ()
		{
			this._document.execCommand("outdent",false,null);
		},
		indentIncrease : function ()
		{
			this._document.execCommand("indent",false,null);
		},
		link : function (URL)
		{
			if ((URL != null) && (URL != ""))
			{
				this._document.execCommand("CreateLink", false, URL);
			}
		},
		image : function (URL)
		{
			if ((URL != null) && (URL != ""))
			{
				this._document.execCommand('InsertImage', false, URL);
			}
		},
		table : function (trs, tds, width, height)
		{
			var table, tableHead, tr, td, i, j;

			table = document.createElement("table");
			table.setAttribute("border","1");

			if (width != null)
				table.setAttribute("width", width);
			else
				table.setAttribute("width","200");
			if (height != null)
				table.setAttribute("height", height);
			else
				table.setAttribute("height","200");

			tableHead=document.createElement("thead");
			table.appendChild(tableHead);

			this._document.body.appendChild(table);

			for (i=1;i<=trs;i++)
			{
				tr = document.createElement("tr");
				tableHead.appendChild(tr);
				tr=table.rows[i-1];
				for (j=1;j<=tds;j++)
				{
					td = document.createElement("td");
					td.appendChild(document.createTextNode("\u00a0"));
					tr.appendChild(td);
				}
			}
		},
		getValue : function ()
		{
			return this._document.body.innerHTML;
		}
	}
});
